package com.stylefeng.guns.modular.silk.controller;

import com.stylefeng.guns.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.modular.system.model.Relics;
import com.stylefeng.guns.modular.silk.service.IRelicsService;

/**
 * 丝绸文物管理控制器
 *
 * @author fengshuonan
 * @Date 2018-04-27 15:03:55
 */
@Controller
@RequestMapping("/relics")
public class RelicsController extends BaseController {

    private String PREFIX = "/silk/relics/";

    @Autowired
    private IRelicsService relicsService;

    /**
     * 跳转到丝绸文物管理首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "relics.html";
    }

    /**
     * 跳转到添加丝绸文物管理
     */
    @RequestMapping("/relics_add")
    public String relicsAdd() {
        return PREFIX + "relics_add.html";
    }

    /**
     * 跳转到修改丝绸文物管理
     */
    @RequestMapping("/relics_update/{relicsId}")
    public String relicsUpdate(@PathVariable Integer relicsId, Model model) {
        Relics relics = relicsService.selectById(relicsId);
        model.addAttribute("item",relics);
        LogObjectHolder.me().set(relics);
        return PREFIX + "relics_edit.html";
    }

    /**
     * 获取丝绸文物管理列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return relicsService.selectList(null);
    }

    /**
     * 新增丝绸文物管理
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(Relics relics) {
        relicsService.insert(relics);
        return SUCCESS_TIP;
    }

    /**
     * 删除丝绸文物管理
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer relicsId) {
        relicsService.deleteById(relicsId);
        return SUCCESS_TIP;
    }

    /**
     * 修改丝绸文物管理
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(Relics relics) {
        relicsService.updateById(relics);
        return SUCCESS_TIP;
    }

    /**
     * 丝绸文物管理详情
     */
    @RequestMapping(value = "/detail/{relicsId}")
    @ResponseBody
    public Object detail(@PathVariable("relicsId") Integer relicsId) {
        return relicsService.selectById(relicsId);
    }
}
